class Reply < ActiveRecord::Base
  belongs_to :post, :counter_cache => true
  belongs_to :user, :counter_cache => true
  
  #validates_presence_of     :content, :message => "内容不能为空"
  
  validates_length_of       :title,    :within => 2..80, :too_long => "标题长度在2到80之间", :too_short => "标题长度在2到80之间"
  validates_length_of       :content,    :within => 1..2000, :too_long => "内容长度在2到2000之间", :too_short => "内容长度在2到2000之间"
  
  def user_has_auth_destroy?(user)
  	return true if user == self.user
  	if self.post.class == GroupPost && self.post.group.is_admin?(user)
  		return true
  	else
  		return false
  	end
  end
  
  def before_save
    self.title = self.title.gsub(/^\<(script|frame)/i, '')
    self.content = self.content.gsub(/^\<(script|frame)/i, '')
  end
end
